home *** CD-ROM | disk | FTP | other *** search
/ Die Ultimative Software-P…i Collection 1996 & 1997 / Die Ultimative Software-Pakete CD-ROM fur Atari Collection 1996 & 1997.iso / p / portfoli / pgc / pgcspec.txt < prev    next >
Encoding:
Text File  |  1996-10-30  |  6.0 KB  |  164 lines

  1.  
  2.    PGC Portfolio Graphics Compressed File Specification
  3.    ----------------------------------------------------
  4.    by Don Messerli, Software Vineyard
  5.    Revision 01      1/4/91
  6.  
  7.    Introduction
  8.    ------------
  9.  
  10.    The PGC spec allows graphic files on the Portfolio (formerly called
  11.    PGF files) to be compressed to save disk (RAM Card) space. We
  12.    all know how much RAM cards cost!
  13.  
  14.    A little background
  15.    -------------------
  16.  
  17.    The Portfolio's screen is 240 x 64 pixels when in graphics mode.
  18.    Being monochome, it only takes 1 bit to represent a single pixel.
  19.    Therefore, 8 pixels per byte.  A PGF ends up being 64 rows of
  20.    30 bytes each for a total of 1920 bytes.  PGF files could simply
  21.    be copied from video ram to disk and vice-versa.
  22.  
  23.    This was pretty simple.  All PGF files were 1920 bytes no matter
  24.    how complex the picture.  A real space waster in most cases.
  25.    Compression became a logical next step.
  26.  
  27.    What will compression do?
  28.    -------------------------
  29.  
  30.    Compression can save quite a bit of space.  Typically from 20
  31.    to 80% depending on the file.  However, because of the compression
  32.    algorithm I have chosen, it is also possible for a file to become
  33.    larger.  This happens with files that have a lot of random dots
  34.    on the screen with little repetition.  Digitized photos are the
  35.    culprits.  Fortunately, because of the small size of the Portfolio
  36.    screen, we probably won't be seeing too many of them.
  37.  
  38.    PGC File Format
  39.    ---------------
  40.  
  41.    Header -   The first 3 bytes of the file are the PGC header.  This
  42.             is the only way to tell if the file is a PGC file or
  43.             not.  This should always be checked when reading PGC
  44.             files.  Your decoder routines could take a quick trip
  45.             into never-never land if you try to decode a spreadsheet
  46.             file.
  47.  
  48.             The three bytes that make up the header are the ASCII
  49.             codes for 'P' and 'G' followed by the revision number
  50.             in hex.  These three bytes should be:
  51.  
  52.                      "\x50\x47\x01" 
  53.                         P    G   01
  54.  
  55.    Data -   The picture data is made up of repeating sets of single
  56.             index bytes followed by data bytes.  The index byte
  57.             tells the decoder how to handle the data that follows.
  58.             The key is whether the high bit (\x80) is set or not.
  59.             The maximum number of data bytes following an index
  60.             byte is 127.
  61.  
  62.             High Bit Set
  63.             ------------
  64.             If the high bit is set, it indicates that the data is
  65.             a string of identical bytes.  The low 7 bits indicate
  66.             how many times to repeat the following byte (maximum is
  67.             127).
  68.  
  69.             Example:  86     FF
  70.                       index  data byte
  71.  
  72.                High bit of index byte is set, low 7 bits = 6.
  73.                Repeat data byte (FF) 6 times.
  74.                      
  75.             High Bit Not Set
  76.             ----------------
  77.             If the high bit is NOT set, it indicates that the data
  78.             following is a string of unique bytes and should be copied
  79.             as is.  The low 7 bits indicate how many bytes to copy (max
  80.             is 127).
  81.  
  82.             Example:  0A     FF 01 10 09 1A BB CE D0 FF 1A
  83.                       index  data bytes
  84.  
  85.                High bit of index byte is NOT set, low 7 bits = 10.
  86.                Copy next 10 bytes as is.
  87.  
  88.    
  89.    Where do we go from here?
  90.    -------------------------
  91.  
  92.    Writing a decoder is fairly straightforward.  The following is
  93.    the general algorithm:
  94.  
  95.    do {
  96.       get a byte from PGC image
  97.       if high bit is set
  98.          index = byte - 128
  99.          get data byte
  100.          write data byte, index times
  101.       else
  102.          index = byte
  103.          copy next index # of bytes
  104.    } while less than 1920 bytes written
  105.    
  106.    Writing an efficient compressor is a little more difficult.  I
  107.    plan to upload a library of functions in the near future.  If
  108.    you encounter difficulty writing a compressor, please contact
  109.    me via electronic mail.
  110.  
  111.  
  112.    What are these other files?
  113.    ---------------------------         
  114.    I have included a few PGF files to give your compressors and
  115.    decoders a real workout.  
  116.  
  117.    BEST.PGF - This is a pure black image.  It should compress down
  118.                to 35 bytes.
  119.  
  120.    WORST.PGF - This image is made up of runs of 2 identical bytes
  121.                alternated with single unique bytes.  It should end
  122.                up being larger as a PGC file (2524 bytes) than as
  123.                a PGF file (1920 bytes). All decoders should be able
  124.                to handle this file.
  125.                
  126.             
  127.    In Closing
  128.    ----------
  129.  
  130.    I hope this information is helpful for those writing graphics
  131.    applications for the Portfolio.  It is my sincere wish that the
  132.    PGC format is widely supported in the Portfolio arena and that
  133.    it promotes compatibility between graphics applications on the
  134.    Portfolio.  My sincere thanks to BJ Gleason for including PGC
  135.    support in PBASIC.  That is a major step in making my wish come
  136.    true.
  137.  
  138.    Please support the PGC format whenever possible.  If your application
  139.    must output PGF files, because you're trying to write the world's
  140.    smallest TSR (or something) and you can't commit to the overhead
  141.    required by a compressor, that is unavoidable.  The PGF files can
  142.    later be compressed with PGCOMP (my compressor).  It is still preferable
  143.    to store files that end up larger as PGC files as PGC files anyway.
  144.    This means software only has to worry about reading the PGC
  145.    format.
  146.  
  147.    Versions of PGEDIT greater than 1.10 will read either PGF or PGC files.
  148.    However, they will only save in PGC format.  BJ Gleason has indicated
  149.    that PBASIC 3.1 will only read and write PGC files.
  150.  
  151.    If you have any questions, comments, or kind words, please send
  152.    me electronic mail:
  153.  
  154.    Don Messerli
  155.    Compuserve    72500,1671
  156.    GEnie         DMESS
  157.  
  158.  
  159.    
  160.  
  161.             
  162.                
  163.  
  164.